package com.groupbuying.payproducer.service.impl;

import com.groupbuying.payproducer.dao.PayOrderRelDao;
import com.groupbuying.payproducer.domain.PayOrderRelDO;
import com.groupbuying.payproducer.utils.BeanOrMapConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.groupbuying.payproducer.dao.PayInfoDao;
import com.groupbuying.payproducer.domain.PayInfoDO;
import com.groupbuying.payproducer.service.PayInfoService;



@Service
public class PayInfoServiceImpl implements PayInfoService {
	@Autowired
	private PayInfoDao payInfoDao;
	@Autowired
	private PayOrderRelDao payOrderRelDao;
	
	@Override
	public PayInfoDO get(String id){
		return payInfoDao.get(id);
	}
	
	@Override
	public List<PayInfoDO> list(Map<String, Object> map){
		return payInfoDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return payInfoDao.count(map);
	}
	
	@Override
	public int save(PayInfoDO payInfo){
		return payInfoDao.save(payInfo);
	}
	
	@Override
	public int update(PayInfoDO payInfo){
		return payInfoDao.update(payInfo);
	}
	
	@Override
	public int remove(String id){
		return payInfoDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return payInfoDao.batchRemove(ids);
	}

	@Override
	public Map<String,String> getPayInfoByOrderId(String orderId) {
		Map<String,String> result = new HashMap<>();
		if (StringUtils.isEmpty(orderId)){
			return null;
		}
		try {
			PayOrderRelDO payOrderRelDO = payOrderRelDao.getByOrderId(orderId);
			PayInfoDO payInfoDO = payInfoDao.get(payOrderRelDO.getId());
			result = BeanOrMapConvertUtils.objectToMapWithoutBlank(payInfoDO);
			result.put("outTradeNo",payOrderRelDO.getOutTradeNo());
		}catch (Exception e){
			e.printStackTrace();
		}
		return result;
	}


}
